<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API
|--------------------------------------------------------------------------
|
| 对前端提供的API支持路由
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function ($api) {

	$namespaceStr = 'App\Http\Controllers\API';
	
	$api->group(['middleware' => ['api', 'cors'], 'namespace' => $namespaceStr], function ($api) {

        /**
         * 用户认证API
         * @var 注册          register
         * @var 登录          login
         * @var 验证码         verification
         * @var 重置密码前验证  reset/comfirm
         * @var 重置密码        reset
         */
        $api->post('register', 'Auth\AuthController@register');
        $api->post('login', 'Auth\AuthController@login');
        $api->post('verification', 'Auth\AuthController@getVerificationCode');
        $api->post('reset/comfirm', 'Auth\AuthController@resetConfirm');
        $api->post('reset', 'Auth\AuthController@reset');

        /**
         * 获取学校信息
         */
        $api->get('colleges', 'Manager\SchoolInfoController@getCollege');
        $api->get('professionals', 'Manager\SchoolInfoController@getProfessional');

        // jwt.auth
        $api->group(['middleware' => 'jwt.auth'], function ($api) {

            /**
             * 首页 - 用户登录后的请求
             * @var
             */
            $api->get('i', 'Home\HomeController@index');
            $api->get('home', 'Home\HomeController@fetch');

            /**
             * 发现
             * @var
             */
            $api->get('find', 'Find\FindController@index');
            $api->get('find/girls', 'Find\FindController@girls');
            $api->get('find/boys', 'Find\FindController@boys');
            $api->get('find/search', 'Find\FindController@search');

            /**
             * @var 创建用户资料         user             post
             * @var 展示用户资料         user/{id}        get
             * @var 头像、背景、姓名的修改 uploadStore/{id} post
             * @var 用户资料更新         user/{id}        post
             */
            $api->resource('user', 'Manager\UserController');
            $api->post('user/{id}', 'Manager\UserController@update');
            // $api->post('uploadStore/{id}', 'Manager\UserController@uploadStore');

            /**
             * @var 展示活动 activity               get
             * @var 参加活动 activity/{userId}/join get
             * @var 其他用户 activity/user          get
             * @var 创建活动 activity               post
             * @var 更新活动 activity/{id}          post
             * @var 删除活动 activity/delete/{id}   post
             */
            $api->get('activity', 'Activity\ActivityController@fromMe');
            $api->get('activity/join', 'Activity\ActivityController@join');
            $api->get('activity/user', 'Activity\ActivityController@fromUser');
            $api->post('activity', 'Activity\ActivityController@store');
            $api->post('activity/{id}', 'Activity\ActivityController@update');
            $api->post('activity/delete/{id}', 'Activity\ActivityController@destroy');

            /**
             * @var 单个活动详情 activity/show/{id}         get
             * @var 活动的申请者 activity/show/{id}/apply   get
             * @var 活动的加入者 activity/show/{id}/join    get
             * @var 获取活动评论 activity/show/{id}/comment get
             */
            $api->get('activity/show/{id}', 'Activity\ActivityController@show');
            $api->get('activity/show/{id}/apply', 'Activity\ApplyController@index');
            $api->get('activity/show/{id}/join', 'Activity\JoinController@index');
            $api->get('activity/show/{id}/comment', 'Activity\CommentController@index');

            /**
             * @var 申请加入活动 activity/apply/{id}          post
             * @var 取消加入活动 activity/apply/cancel/{id}   post
             * @var 允许加入活动 activity/join/{id}           post
             * @var 取消加入活动 activity/join/cancel/{id}    post
             * @var 发布活动评论 activity/comment/{id}        post
             * @var 删除活动评论 activity/comment/{id}/delete post
             */
            $api->post('activity/apply/{id}', 'Activity\ApplyController@apply');
            $api->post('activity/apply/cancel/{id}', 'Activity\ApplyController@cancel');
            $api->post('activity/join/{id}', 'Activity\JoinController@join');
            $api->post('activity/join/cancel/{id}', 'Activity\JoinController@cancel');
            $api->post('activity/comment/{id}', 'Activity\CommentController@store');
            $api->post('activity/comment/{id}/delete', 'Activity\CommentController@destroy');

            /**
             * @var 好友列表 friends/{userId}    get
             * @var 用户信息 friends/{id}/detail get
             * @var 删除好友 friends/{id}        post
             */
            $api->get('friends', 'Friend\FriendController@index');
            $api->get('chatroom/{userId}/to/{companionId}', 'Friend\FriendController@chatroom');
            // $api->post('friends/{friend_id}', 'Friend\FriendController@destroy');

            /**
             * @var 查看历史 chat/{chatRoomId} get
             * @var 更新状态 chat/status post
             * @var 信息发送 chat              post
             * @var 删除信息 chat/{id}         post
             */
            $api->get('chat/{chatRoomId}', 'Friend\ChatController@index');
            $api->post('chat/status', 'Friend\ChatController@status');
            $api->post('chat', 'Friend\ChatController@chat');
            // $api->post('chat/{id}', 'Friend\ChatController@destroy');

            /**
             * @var tweet显示 tweet                 get
             * @var tweet发布 tweet                 post
             * @var tweet删除 tweet/{id}            post
             * @var tweet点赞 tweet/like            post
             * @var tweet取消点赞 tweet/like/cancel post
             * @var tweet评论 tweet/comment         post
             * @var tweet显示评论 tweet/comment/{id} get  <-tweetID
             * @var tweet删除评论 tweet/comment/{id} post
             */
            $api->get('tweet/{userId}', 'Tweet\TweetController@index');
            $api->post('tweet', 'Tweet\TweetController@tweet');
            $api->post('tweet/{id}', 'Tweet\TweetController@destroy');

            /**
             * 通知
             * @var 显示通知 n/{userId}   get
             * @var 标记通知 n/check/{id} get
             * @var 删除通知 n/{id}       post
             */
            $api->get('n', 'Notification\NotificationController@index');
            $api->get('n/check/{id}', 'Notification\NotificationController@check');
            $api->post('n/{id}', 'Notification\NotificationController@destroy');

            /**
             * 反馈
             * @var 提交反馈 feedback post
             */
            $api->post('feedback', 'Feedback\FeedbackController@store');
        });
    });
});
